package com.shop.item.atom.atomsvc.impl;

import com.shop.common.model.ServiceBean;
import com.shop.common.model.param.item.ItemEditHisInput;
import com.shop.common.model.param.item.ItemPriceHisInput;
import com.shop.common.model.result.item.ItemEditHisOutput;
import com.shop.common.model.result.item.ItemPriceHisOutput;
import com.shop.common.tmpl.BaseService;
import com.shop.item.atom.atomsvc.IItemEditAtomService;
import com.shop.item.atom.dao.ItemEditHisMapper;
import com.shop.item.atom.dao.ItemPriceHisMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ItemEditAtomService extends BaseService implements IItemEditAtomService {
    @Autowired
    ItemEditHisMapper itemEditHisMapper;
    @Autowired
    ItemPriceHisMapper itemPriceHisMapper;

    @Override
    public ServiceBean<Integer> insertItemEditHis(ItemEditHisInput editHisInput) {
        if (opSuccess(itemEditHisMapper.insertSelective(editHisInput))) {
            return resultSuccess();
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<String> deleteItemEditHis(ItemEditHisInput editHisInput) {
        if (opSuccess(itemEditHisMapper.deleteByPrimaryKey(editHisInput.getId()))) {
            return resultSuccess();
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<ItemEditHisOutput> selectItemEditHis(ItemEditHisInput editHisInput) {
        ItemEditHisOutput itemEditHisOutput = itemEditHisMapper.selectByPrimaryKey(editHisInput.getId());
        if (itemEditHisOutput != null) {
            return resultData(itemEditHisOutput);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<List<ItemEditHisOutput>> selectItemEditHisList(ItemEditHisInput editHisInput) {
        List<ItemEditHisOutput> list = itemEditHisMapper.selectList(editHisInput.getItemId());
        if (list != null && list.size() > 0) {
            return resultData(list);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<String> updateItemEditHis(ItemEditHisInput editHisInput) {
        return null;
    }

    @Override
    public ServiceBean<Integer> insertItemPriceHis(ItemPriceHisInput priceHisInput) {
        if (opSuccess(itemPriceHisMapper.insertSelective(priceHisInput))) {
            return resultSuccess();
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<String> deleteItemPriceHis(ItemPriceHisInput priceHisInput) {
        if (opSuccess(itemPriceHisMapper.deleteByPrimaryKey(priceHisInput.getId()))) {
            return resultSuccess();
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<ItemPriceHisOutput> selectItemPriceHis(ItemPriceHisInput priceHisInput) {
        ItemPriceHisOutput itemPriceHisOutput = itemPriceHisMapper.selectByPrimaryKey(priceHisInput.getId());
        if (itemPriceHisOutput != null) {
            return resultData(itemPriceHisOutput);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<List<ItemPriceHisOutput>> selectItemPriceHisList(ItemPriceHisInput priceHisInput) {
        List<ItemPriceHisOutput> list = itemPriceHisMapper.selectList(priceHisInput.getId());
        if (list != null && list.size() > 0) {
            return resultData(list);
        }
        return resultFailed();
    }

    @Override
    public ServiceBean<String> updateItemPriceHis(ItemPriceHisInput priceHisInput) {
        return null;
    }
}
